<?php
namespace My\Model;

use Utuo\UtuoModel;

class ActivityScratchModel extends UtuoModel {

	protected $_auto = array(
			array('prize_config', 'getConfig', self::MODEL_BOTH, 'callback'),
			array('begin_time', 'getBeginTime', self::MODEL_BOTH, 'callback'),
			array('end_time', 'getEndTime', self::MODEL_BOTH, 'callback'),
	);
	
	/**
	 * 	$config = array(
	 * 		array('total' => 5, 'count' => 1, 'ratio' => 56, 'title'=> '一等奖', 'prizeName'=>"精美礼品"),
	 * 		array('total' => 10, 'count' => 2, 'ratio' => 60, 'title'=> '二等奖', 'prizeName'=>"精美礼品"),
	 * 		array('total' => 20, 'count' => 3, 'ratio' => 70, 'title'=> '三等奖', 'prizeName'=>"精美礼品"),
	 * 	)
	 * @return boolean
	 */
	public function getConfig() {
		$config = I("prize_config");
		if(!isset($_REQUEST['prize_config'])) return false;
		$i=0;
		foreach ($config as $k => &$v) {
			$v['level'] = ++$i;
		}
		return serialize(array_values($config));
	}
	
	/**
	 * 开始时间
	 * @return boolean|number
	 */
	public function getBeginTime() {
		$beginTime = I("begin_time");
		if(!isset($_REQUEST['begin_time'])) return false;
		return strtotime($beginTime);
	}
	
	/**
	 * 结束时间 
	 * @return boolean|number
	 */
	public function getEndTime() {
		$endTime = I("end_time");
		if(!isset($_REQUEST['end_time'])) return false;
		return strtotime($endTime);
	}
	

}